home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / pdcurs21.zip / PORTABLE.ZIP / NEWWIN.C < prev    next >
Text File  |  1992-11-21  |  4KB  |  101 lines

  1. #include <stdlib.h>
  2. #define        CURSES_LIBRARY  1
  3. #include <curses.h>
  4. #undef newwin
  5.  
  6. #ifndef        NDEBUG
  7. char *rcsid_newwin = "$Header: c:/curses/portable/RCS/newwin.c%v 2.0 1992/11/15 03:29:28 MH Rel $";
  8. #endif
  9.  
  10.  
  11.  
  12.  
  13. /*man-start*********************************************************************
  14.  
  15.   newwin()     - create new window
  16.  
  17.   X/Open Description:
  18.        Create a new window with the given number of lines, nlines and
  19.        columns, ncols. The upper left corner of the window is at line
  20.        begy, column begx. If either nlines or ncols is zero,
  21.        they will be defaulted to LINES - begy and COLS - begx. A
  22.        new full-screen window is created by calling newwin(0, 0, 0, 0).
  23.  
  24.   PDCurses Description:
  25.        PDCurses allows developers to provide a hook into the malloc
  26.        package used.  See initscr(3c) for more details.
  27.  
  28.        Also, when a window is created, it uses the default screen
  29.        colors and attributes in effect when initscr() was called.
  30.  
  31.   X/Open Return Value:
  32.        On success the newwin() function returns a pointer to the new
  33.        WINDOW structure created. On failure the function returns a
  34.        null pointer.
  35.  
  36.   PDCurses Errors:
  37.        The following conditions are errors:
  38.                o  number of lines   == 0,
  39.                o  number of columns == 0,
  40.                o  failure to allocate memory for the window structure
  41.  
  42.   Portability:
  43.        PDCurses        WINDOW* newwin(int nlines,int ncols,int begy,int begx);
  44.        X/Open Dec '88  WINDOW* newwin(int nlines,int ncols,int begy,int begx);
  45.        BSD Curses      WINDOW* newwin(int nlines,int ncols,int begy,int begx);
  46.        SYS V Curses    WINDOW* newwin(int nlines,int ncols,int begy,int begx);
  47.  
  48. **man-end**********************************************************************/
  49.  
  50. WINDOW*        newwin(int nlines, int ncols, int begy, int begx)
  51. {
  52. extern void*   (*mallc)( size_t );
  53. extern void*   (*callc)( size_t, size_t );
  54. extern void    (*fre)( void* );
  55.  
  56.        WINDOW* win;
  57.        chtype* ptr;
  58.        int     i;
  59.        int     j;
  60.  
  61.        if (nlines == 0)        nlines = LINES - begy;
  62.        if (ncols  == 0)        ncols  = COLS  - begx;
  63.  
  64.        if ((win = PDC_makenew(nlines, ncols, begy, begx)) == (WINDOW *) NULL)
  65.                return( (WINDOW *)NULL );
  66.  
  67.        for (i = 0; i < nlines; i++)
  68.        {
  69.                /*
  70.                 * make and clear the lines
  71.                 */
  72.                if ((win->_y[i] = (*callc)(ncols, sizeof(chtype))) == NULL)
  73.                {
  74.                        for (j = 0; j < i; j++)
  75.                        {
  76.                                /*
  77.                                 * if error, free all the data
  78.                                 */
  79.                                (*fre)(win->_y[j]);
  80.                        }
  81.                        (*fre)(win->_firstch);
  82.                        (*fre)(win->_lastch);
  83.                        (*fre)(win->_y);
  84.                        (*fre)(win);
  85.                        return( (WINDOW *)NULL );
  86.                }
  87.                else
  88.                {
  89.                        for (ptr = win->_y[i];
  90.                             ptr < win->_y[i] + ncols;)
  91.                        {
  92.                                /*
  93.                                 * Retain the original screen attributes...
  94.                                 */
  95.                                *ptr++ = _cursvar.blank;
  96.                        }
  97.                }
  98.        }
  99.        return( win );
  100. }
  101.